package cn.xerllent.common.entity.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import lombok.Data;

@Data
@JsonInclude(value = Include.NON_NULL)   //生成json时，null属性不输出
public class ResultData {
	private Integer code;	//类似header的status,前端可以读取header的status
	private String msg; 	//可以自定义返回消息，前端一般根据status或code代码翻译成具体消息，可以忽略
	private Object data; 	//前端定义的返回数据体
	
	private ResultData() {
	}

	public static ResultData data(Object data) {
		ResultData a = new ResultData();
		a.data = data;
		return a;
	}

	public static ResultData data(Object data, String msg) {
		ResultData a = new ResultData();
		a.data = data;
		a.msg = msg;
		return a;
	}
	
	public static ResultData msg(String msg) {
		ResultData a = new ResultData();
		a.msg = msg;
		return a;
	}
	
	public static ResultData msg(String msg, Integer code) {
		ResultData a = new ResultData();
		a.msg = msg;
		a.code = code;
		return a;
	}
	
	public static ResultData err(String msg) {
		ResultData a = new ResultData();
		a.msg = msg;
		a.code = 400; //默认错误类型
		return a;
	}

}